<?php
/**
 * Created by PhpStorm.
 * User: kamlyli
 * Date: 2017/7/22
 * Time: 13:42
 */

namespace app\api\validate;


use think\Validate;

// 验证器
class IDMustBePostiveInt extends BaseValidate
{
    // 定义
    protected $rule = [
        'id' => 'require|max:10|isPositiveInteger',
    ];

    // 如果内置规则没有，就要手撸
    // 判断是不是正整数
    protected function isPositiveInteger($value, $rule = '', $data = '', $field = '')
    {
        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
            return true;
        } else {
            return $field.'必须为正整数';
        }
    }
}